<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/2
 * Time: 17:13
 */
include "config.php";
if($_SERVER["REQUEST_METHOD"]=="POST"){
    if(!empty($_POST["uname"])&&!empty($_POST["upwd"])&&!empty($_POST["utel"])){
        $name=$_POST["uname"];
        $pwd=$_POST["upwd"];
        $tel=$_POST["utel"];
        $readySql="SELECT * FROM fashionshopping.userinfo WHERE u_name=?";
        $stmt=$conn->prepare($readySql);
        $stmt->bind_param("s",$name);
        $stmt->execute();
        $result=$stmt->get_result();
        if($result->num_rows<1){
            $inserSQL = "INSERT INTO fashionshopping.`userinfo` (`u_name`,`u_pwd`,`u_tel`)VALUES(?,?,?)";
            //2.预执行
            $stmt1 = $conn->prepare($inserSQL);
            $stmt1->bind_param("sss", $_REQUEST["uname"], $_REQUEST["upwd"], $_REQUEST["utel"]);
            $stmt1->execute();
            if($stmt1->affected_rows >= 1){
                print_r(json_encode(Array("status" => 1, "msg" => "恭喜,注册成功")));
            } else {
                print_r(json_encode(Array("status" => 0, "msg" => "注册失败","data"=>"错误信息:".$stmt->errno)));
            }
        }else{
            print_r(json_encode(Array("status"=>0,"msg"=>"用户名已经存在")));
        }
    }else{
        print_r(json_encode(Array("status"=>0,"msg"=>"请输入正确参数")));
    }
}else{
    print_r(json_encode(Array("status"=>0,"msg"=>"请使用post请求")));
}